package com.admin;


import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.po.Admin;

@Controller
@RequestMapping("/admin")
public class IndexController {
	@RequestMapping("")
	public String index(Model model) {
		model.addAttribute("admin",new Admin());
		return "login";
	}
	@RequestMapping("/login")
	public String login(String username,String password) {
		Subject subject = SecurityUtils.getSubject();
		UsernamePasswordToken token = new UsernamePasswordToken(username,password);
		try {
			System.out.println(username);
			System.out.println(password);
			subject.login(token);
			return "redirect:/admin/index";
		}catch(AuthenticationException e){
			
			e.printStackTrace();
			return "/error";
		}
		
		
	}
	@RequestMapping("/index")
	public String realmindex() {
		return "index";
	}
	
	@RequestMapping("/add")
	public String add() {
		return "add";
	}
	
	@RequestMapping("/manager")
	public String manager() {
		return "manager";
	}
	@RequestMapping("/category")
	public String category() {
		return "category";
	}
}
